package inabit.expressioncompiler.parser;

import inabit.compiler.parser.SemanticAction;
import inabit.compiler.parser.grammar.NonTerminal;
import inabit.data.InabitMethod;
import inabit.data.expression.Expression;
import inabit.data.expression.arithmetic.ArithmeticExpression;
import inabit.inabitcompiler.parser.ArithmeticExpressionMap;
import inabit.inabitcompiler.parser.ExpressionMap;

import java.util.HashMap;
import java.util.Map;
/**@author Rafael Rocha*/
public abstract class ExpressionSemanticAction extends SemanticAction{
	private ArithmeticExpression expression;
	private Map<String, InabitMethod> methods;
	
	public ExpressionSemanticAction(NonTerminal nonTerminal) {
		super(nonTerminal);
		methods = new HashMap<String, InabitMethod>();
	}
	
	public ArithmeticExpression getExpression() {
		return expression;
	}
	public void setArithmeticExpression(ArithmeticExpression exp) {
		this.expression = exp;
	}
	
	/**Add the expression to expression base and returns the id of the exp at the base*/
	public String addExpressionAndGetCode(Expression exp) {
		String id = ExpressionMap.getInstance().addExpression(exp);
		return id;
	}
	
	public ArithmeticExpression getArithmeticExpression(String id) {
		return ArithmeticExpressionMap.getInstance().getExpression(id);
	}
	
	public String addArithmeticExpressionAndGetCode(ArithmeticExpression exp) {
		return ArithmeticExpressionMap.getInstance().addExpression(exp);
	}

	public InabitMethod getMethod(String methodName){
		return methods.get(methodName);
	}
	public void setMethods(Map<String, InabitMethod> methods) {
		this.methods = methods;
	}

}
